.TH std::basic_string::empty 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::basic_string::empty \- std::basic_string::empty

.SH Synopsis
   bool empty() const;  (noexcept since C++11)
                        (constexpr since C++20)

   Checks if the string has no characters, i.e. whether begin() == end().

.SH Parameters

   \fI(none)\fP

.SH Return value

   true if the string is empty, false otherwise

.SH Complexity

   Constant.

.SH Example


// Run this code

 #include <iostream>
 #include <string>

 int main()
 {
     std::string s;
     std::boolalpha(std::cout);
     std::cout << "s.empty():" << s.empty() << "\\t s:'" << s << "'\\n";

     s = "Exemplar";
     std::cout << "s.empty():" << s.empty() << "\\t s:'" << s << "'\\n";

     s = "";
     std::cout << "s.empty():" << s.empty() << "\\t s:'" << s << "'\\n";
 }

.SH Output:

 s.empty():true   s:''
 s.empty():false  s:'Exemplar'
 s.empty():true   s:''

.SH See also

   size     returns the number of characters
   length   \fI(public member function)\fP
   max_size returns the maximum number of characters
            \fI(public member function)\fP
            returns the number of characters that can be held in currently allocated
   capacity storage
            \fI(public member function)\fP
   size
   ssize    returns the size of a container or array
   \fI(C++17)\fP  \fI(function template)\fP
   (C++20)
   empty    checks whether the container is empty
   \fI(C++17)\fP  \fI(function template)\fP
   empty    checks whether the view is empty
            \fI(public member function of std::basic_string_view<CharT,Traits>)\fP
